/* 
 * UrlyBirdReg.java 01.08.2011
 *  
 *  
 * Candidate: Alessandra Otterbach
 * Prometric ID: Algisina1
 * Username: Algisina
 *  
 * Sun Certified Developer for Java 2 Platform, Standard Edition Programming 
 * Assignment (CX-310-252A)
 *  
 * This class is part of the Programming Assignment of the Sun Certified 
 * Developer for Java 2 Platform, Standard Edition certification program, must 
 * not be used out of this context and must be used exclusively by Sun 
 * Microsystems, Inc. 
 */
package suncertify.rm;

import java.net.MalformedURLException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import suncertify.bs.RemoteBusinessService;
import suncertify.bs.RemoteBusinessServiceImpl;

/**
 * @author Alessandra Otterbach
 * 
 */
public class UrlyBirdReg {
    /**
     * Since this is a utility class (it only exists for other classes to call
     * it's static methods), lets stop users creating unneeded instances of this
     * class by creating a private constructor.
     */
    private UrlyBirdReg() {
    }

    /**
     * Creates the DvdDatabase class and binds it to the name "DvdDatabase".
     * 
     * @throws RemoteException
     *             on network error.
     * @throws MalformedURLException
     */
    public static void register() throws RemoteException {
	register(".", java.rmi.registry.Registry.REGISTRY_PORT);
    }

    public static void register(String path, int rmiPort)
	    throws RemoteException {

	// RemoteBusinessServiceImpl remoteService = new
	// RemoteBusinessServiceImpl(
	// path);
	// RemoteBusinessService stub = (RemoteBusinessService)
	// UnicastRemoteObject
	// .exportObject(remoteService, Registry.REGISTRY_PORT);
	//
	// Registry registry = LocateRegistry.getRegistry();
	// registry.rebind("RemoteBusinessService", stub);

	RemoteBusinessService server = (RemoteBusinessService) UnicastRemoteObject
		.exportObject(new RemoteBusinessServiceImpl(path), rmiPort);
	Registry registry = LocateRegistry
		.createRegistry(Registry.REGISTRY_PORT);
	registry.rebind("RemoteBusinessService", server);

	// LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
	// Registry registry = java.rmi.registry.LocateRegistry
	// .createRegistry(rmiPort);

	// registry.rebind("URLyBird", new UrlyBirdDataFactoryImpl(path));
    }
}
